#pragma once
#include "helper/SMatrix.h"
class CMainDlg;

namespace SOUI{
	class SKnob : public SWindow
{
	SOUI_CLASS_NAME(SKnob, L"knob")

public:
	SKnob();
	//SKnob(CMainDlg *pDlgMain);
	void SetDlgMain(CMainDlg *pDlgMain) {
		m_pDlgMain = pDlgMain;
	}
	void sendDataToCmark(const char *data);
	void    SetValue(FLOAT angle);
	BOOL  GetChanging() { return m_isChanging; }

	enum {TIMER_REFRESH = 1};

protected:
    SMatrix InitMatrix(double angle, CPoint &center);

    double GetMinuteSecondAngle(int nValue);
    double GetHourAngle(int nHour,int nMinute);

protected:
	int  OnCreate(void*);
	void OnPaint(SOUI::IRenderTarget * pRT);
	void OnTimer(char cTimerID);

	void    OnLButtonUp(UINT nFlags, CPoint point);
	void    OnLButtonDown(UINT nFlags, CPoint point);
	void    OnMouseMove(UINT nFlags, CPoint point);
	void    OnMouseLeave();

	SOUI_MSG_MAP_BEGIN()
		MSG_WM_PAINT_EX(OnPaint)
		MSG_WM_TIMER_EX(OnTimer)
		MSG_WM_CREATE(OnCreate)
		MSG_WM_LBUTTONDOWN(OnLButtonDown)
		MSG_WM_LBUTTONUP(OnLButtonUp)
		MSG_WM_MOUSEMOVE(OnMouseMove)
		MSG_WM_MOUSELEAVE(OnMouseLeave)
	SOUI_MSG_MAP_END()

protected:
	SOUI_ATTRS_BEGIN()
		ATTR_IMAGEAUTOREF(L"knob", m_knob, TRUE)
	SOUI_ATTRS_END()

	CAutoRefPtr<IBitmap> m_knob;

	CPoint m_lBtnDownPt;
	CPoint m_centerPt;
	BOOL m_isLBtnDown;
	FLOAT m_angle;

	CMainDlg *m_pDlgMain;
	BOOL m_isChanging;
};

}